package com.sanhe.roller;

import android.app.Activity;

import com.menu.app.MyApp;
import com.menu.app.activity.base.MenuBaseActivity;
import com.menu.app.activity.base.PortBaseActivity;
import com.menu.app.util.Pdf;
import com.menu.app.util.pipe.BasePortEventPipe;
import com.menu.app.util.port.SerialHandler;
import com.sanhe.roller.activity.BoardActivity;
import com.sanhe.roller.activity.SettingMenuActivity;
import com.sanhe.roller.activity.work.ModeActivity;
import com.sanhe.roller.pipe.PortPipe;
import com.sanhe.roller.util.MySerialHandler;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class App extends MyApp {

    static App sInstance;

    @Override
    public String getUmId() {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        sInstance = this;
    }

    @Override
    public void back2Main(MenuBaseActivity.JumpPrepareListener listener) {
        ignore = true;
        Iterator<Activity> it = list.iterator();
        while (it.hasNext()) {
            Activity activity = it.next();
            if (activity instanceof PortBaseActivity && !isWorkingPage()) {
                ((PortBaseActivity) activity).exit();
            }
        }
        if (listener != null) {
            listener.onPrepared();
        }
    }

    @Override
    public boolean isWorkingPage() {
        return false;
    }

    @Override
    public Class getMainClass() {
        return ModeActivity.class;
    }

    public static App getApp() {
        return sInstance;
    }

    @Override
    public Map getPageMap() {
        HashMap<String, Class> router = new HashMap<>();
        router.put("setting", SettingMenuActivity.class);
        return router;
    }

    MySerialHandler serialHandler;

    @Override
    public SerialHandler getSerialHandler(int type) {
        if (serialHandler == null) {
            serialHandler = new MySerialHandler();
        }
        return serialHandler;
    }

    @Override
    public int getRate() {
        return 19200;
    }

    @Override
    public Class getBoard() {
        return BoardActivity.class;
    }

    @Override
    public BasePortEventPipe getPortPipe() {
        return PortPipe.getInstance();
    }

    @Override
    public Class getSettingClass() {
        return SettingMenuActivity.class;
    }

    @Override
    public Class getCustomInfoClass() {
        return null;
    }

    @Override
    public Pdf getPdfCreator() {
        return null;
    }
}

